1. What is parallel sessions and why it's needed?

Parallel sessions allows you to run multiple instance of server virtually while running only one server. This is helpful when you are running multiple test cases which access the same routes but different variants as parallel sessions allow you to set different variants on same routes without conflicting. This saves CPU and RAM both as only one server is running instead of multiple.

2. How Parallel Sessions works internally?

midway_parallel_sessions

3. How to add parallel sessions?

To add parallel sessions, modify run-mock-server-console.js to add 'sessions' parameter.

require('./endpoints');
var midway = require('testarmada-midway');
midway.start({
  host: "localhost",
  mockedDirectory: "./resources/mocked-data",
  port: 8000,
  sessions: 2,
  project: 'HelloMidway'
});

You can also start or add sessions via command line argument

node resources/run-mock-server-console.js --midwaySessions 2

If you pass sessions = 2, there will be two parallel sessions along with one default session.

4. Supported APIs for Parallel sessions

  1. Register Session To register sessions to be used

    var sessionId = midway.registerSession();
    
  2. Get Sessions To get all the active sessions

    var activeSessions = midway.getSessions();
    
  3. Check Session To check the session status (Available or In-Use or invalid)

    var sessionStatus = midway.checkSession(sessionId);
    
  4. Close Session To de-register session for later use

    var closeSession = midway.closeSession(sessionId);
    

5. Using Parallel Sessions

To use a parallel session call the following api:

curl http://localhost:8000/_admin/api/midway/registerSession

or

midway.registerSession()

and a session id will be returned.

Append this sessionId to the mocked host address to use this parallel session. For ex: If your mock host server is http://localhost:8080 and your session id is 112233 then the mock server address for this parallel session will be http://localhost:8080/112233.

6. Verifying parallel sessions

Start mock server with two sessions. Now go to the 'Message' route. You will see three routes for message, default and two for parallel sessions that you just added. Now for each route choose a different variant and hit the URL icon. You will see that each time you will get a different value though you are hitting the same route.

7. Understanding the Midway UI with sessions

Try to go through Midway UI to understand sessions.